# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=libplist
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.3.0
pkgrel=2
pkgdesc='A library to handle Apple Property List format in binary or XML (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://www.libimobiledevice.org/'
license=('spdx:GPL-2.0-or-later AND spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cython")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: Python bindings")
source=("https://github.com/libimobiledevice/libplist/releases/download/${pkgver}/libplist-${pkgver}.tar.bz2"
        002-dont-include-winmain-in-static.patch
        003-fix-py-soext.patch
        004-exports.patch)
sha256sums=('4e8580d3f39d3dfa13cefab1a13f39ea85c4b0202e9305c5c8f63818182cac61'
            '1252c52cbd285a4bef59b0e93d6fcca493e9696c70fa8b22a912f2b13ed0351a'
            'cc1634d07016632633816263d640e7ef5b5bf7b6db72a15a62ce240e9340b032'
            '4047250b0aa9cee2ce8f3d356402deacbf67e6a6b1fd848c3523eaed4b0b6bc8')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/002-dont-include-winmain-in-static.patch
  patch -p1 -i ${srcdir}/003-fix-py-soext.patch
  patch -p1 -i ${srcdir}/004-exports.patch

  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  PYTHON=${MINGW_PREFIX}/bin/python3 \
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-static \
      --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  # || true because of FAIL: bigarraycmp .. File does not exists
  make check || true
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/python*/site-packages/*.a
}
